﻿using System.Collections.Generic;
using System.Linq;

namespace Project5188.BUS.DocumentManagement
{
    public class DocumentFlow : DetailView<documentflow>
    {
        private project5188Entities _context;
        // ReSharper disable InconsistentNaming
        private new List<documentflow> EntityList;
        private new documentflow Entity;
        // ReSharper restore InconsistentNaming

        public long TransactionId { get; private set; }

        #region Overrides of DetailView<documentflow>

        public override List<documentflow> GetEntityList()
        {
            _context = new project5188Entities();
            EntityList = _context.documentflows.Where(a => !a.IsDeleted).OrderBy(a => a.a_ID).ToList();

            return EntityList;
        }

        public override List<documentflow> GetEntityById(long id)
        {
            _context = new project5188Entities();
            EntityList = _context.documentflows.Where(a => a.a_ID == id && !a.IsDeleted).OrderBy(a => a.a_ID).ToList();

            return EntityList;
        }

        public override documentflow GetEntity()
        {
            _context = new project5188Entities();
            Entity = new documentflow();
            return Entity;
        }

        public override void Update()
        {
            _context.SaveChanges();
        }

        public override void Insert()
        {
            _context.AddTodocumentflows(Entity);
            _context.SaveChanges();
            TransactionId = Entity.a_ID;
        }

        public List<documentflow> GetEntityListByParameters(long flowTypeParameterId, long userId)
        {
            _context = new project5188Entities();
            EntityList = _context.documentflows.Where(a => a.document.h_FlowTypeParameterValueID_31 == flowTypeParameterId && a.document.user.ID == userId && !a.IsDeleted).OrderBy(a => a.a_ID).ToList();

            return EntityList;
        }

        #endregion
    }
}
